<?php

class Model_Hr_Taskhistory extends Zend_Db_Table_Abstract {

	protected $_name = 'task_history';
	
	public function getTaskhistory( $idTaskHistory){
		
		$row = $this->fetchRow("`id_task_history` = ". $idTaskHistory);
		if(!$row) return false;
		return $row->toArray();		
		
		}
		
	public function addTaskhistory( $idTask , $idStaff,$dateCreat , $dateComplete){
		
		$data = array(
			
         "id_task" =>  $idTask ,
		 "id_staff" => $idStaff,		
         "date_creat" =>  $dateCreat ,
         "date_complete" =>  $dateComplete 
	
			);
		$this->insert($data);
		
		}
		
	public function updateTaskhistory(  $idTaskHistory ,  $idTask , $idStaff, $dateCreat , $dateComplete){
		$data = array(
			
         "id_task" =>  $idTask ,
		 "id_staff" => $idStaff,
         "date_creat" =>  $dateCreat ,
         "date_complete" =>  $dateComplete 
	
			);
			
		$this->update($data,"`id_task_history` = ". $idTaskHistory);
		}
		
	public function deleteTaskhistory( $idTaskHistory){
		
		$this->delete("`id_task_history` = ". $idTaskHistory);
		
		}	
	
	public function listAll(){
		
		$rows =$this->fetchAll("1","id_task_history DESC ");
		if(!$rows) return false;
		return $rows->toArray();			
		
		}	
		
	public function listTaskByStaff($idStaff){
		$dateToday = Model_DatetimeHelper::dateToday();
		
		$whereStr = "`id_staff` = {$idStaff} AND ( `date_creat` = '".$dateToday."' OR ( `date_creat` < '".$dateToday."' AND `date_complete` IS NULL) )";
		
		$taskList = $this->fetchAll($whereStr,'date_creat');
		
		return $taskList->toArray();
	}
	public function finishTaskSimple($idTaskHistory){
		
		$data = array(
				"date_complete" => Model_DatetimeHelper::dateToday(),
				"time_complete" => Model_DatetimeHelper::dateToday().' '.Model_DatetimeHelper::timeNow()
		);
			
		$this->update($data,"`id_task_history` = ". $idTaskHistory);
		
	}	
}


?>